<include file="public@header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('agent/index')}">代理商列表</a></li>
			<li class="active"><a href="{:url('agent/add')}">添加代理商</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('agent/add')}">
			<div class="form-group">
				<label class="col-sm-2 control-label">
					<span class="form-required">*</span>代理商名称
				</label>
				<div class="col-md-3 col-sm-6">
					<input type="text" class="form-control" name="name">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">
					<span class="form-required">*</span>代理商账号
				</label>
				<div class="col-md-3 col-sm-6">
					<input type="text" class="form-control" name="account">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">
					<span class="form-required">*</span>密码
				</label>
				<div class="col-md-3 col-sm-6">
					<input type="text" class="form-control" name="password">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">
					<span class="form-required">*</span>区域
				</label>
				<div class="col-md-6 col-sm-10">
					<label class="form-inline">
						<select class="form-control" name="province_id" id="province">
	                        <option value="">请选择省</option>
	                    </select>
	                </label>
	                <label class="form-inline">
	                    <select class="form-control" name="city_id" id="city">
	                        <option value="">请选择市</option>
	                    </select>
	                </label>
                    <label class="form-inline">
	                    <select class="form-control" name="area_id" id="area">
	                        <option value="">请选择区</option>
	                    </select>
	                </label>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
				</div>
			</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="text/javascript">
		function get_region_list(parentid,obj)
        {
            $.ajax({
                type:'get',
                url:'{:url("staff/get_region_list")}',
                data:{parentid:parentid},
                success:function(res){
                    var html = '<option value="">请选择</option>';
                    var json = eval(res.data);
                    for (var key in json) {
                    	html += '<option value="'+json[key].id+'" data-id="'+json[key].id+'">'+json[key].areaname+'</option>';
                    }
                    $('#'+obj).html(html);
                }
            });
        }

        get_region_list(0,'province');

        $('#province').change(function(){
            var id = $(this).find("option:selected").attr('data-id');
            get_region_list(id,'city');
            $('#area').html('<option value="">请选择</option>');
        });

        $('#city').change(function(){
            var id = $(this).find("option:selected").attr('data-id');
            get_region_list(id,'area');
        });

        $('.position').click(function(){
        	var checkedValues = $('.position:checked').map(function(){
		        return $(this).val();
		    }).get();

		    if ($.inArray('2', checkedValues) !== -1) {
			    $('.construction_list').show();
			} else {
			    $('.construction_list').hide();
			    $('.construction').prop('checked', false);
			}
        });

	</script>
</body>
</html>